import request from "@/utils/request";
import { ParamsType } from "./type";

/**
 * 获取企业列表信息（所有企业）
 * @param data
 * @returns
 */
export function old_getCorpList(data: ParamsType) {
  return request({
    url: "api/v1/common/corps",
    method: "get",
    params: data,
  });
}

/**
 * 获取总包企业列表信息（总包）
 * @param data
 * @returns
 */
export function getCorpList_zb(data: ParamsType) {
  return request({
    url: "api/v1/manager/common/corps_zb",
    method: "get",
    params: data,
  });
}

/**
 * 获取班组管理企业列表信息（总包+分包）
 * @param data
 * @returns
 */
export function getCorpList_manager(data: ParamsType) {
  let url = `api/v1/manager/common/corps_manager`;
  switch (localStorage.getItem("usertypeName")) {
    case "Corp":
      url = `api/v1/corp/common/corps_manager`;
      break;
    case "Manager":
      url = `api/v1/manager/common/corps_manager`;
      break;
  }

  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 根据id获取企业详情
 * @param corpId
 * @returns
 */
export function getCorpInfoById(corpId: number) {
  return request({
    url: "api/v1/common/corp/" + corpId,
    method: "get",
  });
}

/**
 * 获取企业列表下拉（总包+分包）
 * @param data
 * @returns
 */
export function getProjectCorps(projectId?: number) {
  let url;
  switch (localStorage.getItem(`usertypeName`)) {
    case `Manager`:
      url = `/api/v1/manager/projectgroup/getProjectCorps`;
      break;
    case `Corp`:
      url = `/api/v1/corp/projectgroup/getProjectCorps`;
      break;
    case `Constructor`:
      url = `/api/v1/constructor/projectgroup/getProjectCorps`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectCorps`;
      break;
    case `Commander`:
      url = `/api/v1/commander/projectgroup/getProjectCorps`;
      break;
    case `SysUser`:
      url = `/api/v1/sysuser/projectgroup/getProjectCorps/` + projectId;
      break;
    default:
      url = `/api/v1/manager/projectgroup/getProjectCorps`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取企业注册结果
 * @param id
 * @returns
 */
export function GetCorpRegResult(id: string) {
  return request({
    url: `/api/v1/account/corp_reg_result/${id}`,
    method: "get",
  });
}

/**
 * 查询企业
 * @param keywords
 * @returns
 */
export function SearcChorps(keywords: string) {
  return request({
    url: `/api/v1/common/search_corps`,
    method: "get",
    params: {
      keywords,
    },
  });
}

/**
 * 查询企业(登录)
 * @param keywords
 * @returns
 */
export function SearchFullCorps(keywords: string) {
  return request({
    url: `/api/v1/user_common/search_fullcorps`,
    method: "get",
    params: {
      keywords,
    },
  });
}
